/**
 * @type {import('vuex').Module}
 */
import axios from "axios"
const todolist = {
    namespaced:true,
    state:{
        listTest:[]
    },
    mutations:{
        updateList(state,payload){
            state.listTest = payload
        },
        del(state,id){
            // 获取到选中的这个对象，删除它
            const newList = state.listTest.filter(item=>item.id!==id)
            // console.log(newList)
            state.listTest = newList
        }
    },
    actions:{
        async getList(context){
            const res = await axios({
                method:"GET",
                url:"http://localhost:3000/todoList"
            })
            console.log(res)
            context.commit("updateList",res.data)
        },
        async delList(context,id){
            await axios({
                method:"DELETE",
                url:"http://localhost:3000/todoList/"+ id
            })
            context.commit("del",id)
        }
    }
}

export default todolist